﻿using CommunicationProtocol.dto;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using monoClient.utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static monoClient.utils.Constant;

namespace monoClient.renderer
{
    internal class BuyablePlantRenderer : CommandExecutor
    {

        public Texture2D plantTexture2D { get; }
        public Rectangle plantLocation { get; }
        public BuyablePlantRenderer(StaticPlant staticPlant)
        {
            StaticPlant = staticPlant;

            List<Texture2D> texture2Ds = ImageUtils.loadImagesByObjectType(StaticPlant.ObjectType);

            plantTexture2D = texture2Ds[0];

            plantLocation = new Rectangle(staticPlant.LocationX*30,staticPlant.LocationY, defaultBuyablePlantWidth, defaultBuyablePlantHeight);

            
        }

        public StaticPlant StaticPlant { get; }

        public void Draw(GameTime gameTime, SpriteBatch _spriteBatch)
        {
            _spriteBatch.Draw(plantTexture2D, plantLocation, Color.White);
        }

 
    

        public void Update(GameTime gameTime, MouseState mouseState, MouseState oldMouseState)
        {
            
            if ( mouseState.LeftButton != ButtonState.Pressed  &&oldMouseState.LeftButton == ButtonState.Pressed &&plantLocation.Contains(mouseState.Position) )
            {
                // 鼠标在按钮上点击时执行的操作
                // 例如，打开一个菜单或执行某个功能
                OutBandHolder.send(
                    new CheckBuyablePlantAvailable(
                    StaticPlant.ObjectId.ToString()
                    )
                );
            }
        }
    }
}
